//
//  CustomerController.m
//  i优购商城
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "CustomerController.h"
@interface CustomerController ()

@end

@implementation CustomerController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTabBar];
}


-(void)initTabBar
{
    _tabBarView=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height-50, self.view.bounds.size.width, 50)];
    [self.view addSubview:_tabBarView];
    CGFloat width=_tabBarView.bounds.size.width/self.viewControllers.count;
    NSArray*imageName=@[@"public_toolBar_icon0",@"public_toolBar_icon1",@"public_toolBar_icon2",@"public_toolBar_icon3",@"public_toolBar_icon4"];
    NSArray*selectImageName=@[@"public_toolBar_icon0_selected",@"public_toolBar_icon1_selected",@"public_toolBar_icon2_selected",@"public_toolBar_icon3_selected",@"public_toolBar_icon4_selected"];
    for (int i =0; i<self.viewControllers.count; i++) {
        UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(width*i, 0, width, _tabBarView.bounds.size.height);
        [btn setBackgroundImage:[UIImage imageNamed:imageName[i]] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:selectImageName[i]] forState:UIControlStateDisabled];
        btn.tag=100+i;
        [btn addTarget:self action:@selector(selctorViewController:) forControlEvents:UIControlEventTouchUpInside];
        [_tabBarView addSubview:btn];
        if (i==0) {
            btn.enabled=NO;
        }
    }
    
    
}

-(void)selctorViewController:(UIButton*)sender
{
    for (int i=0; i<self.viewControllers.count; i++) {
        UIButton*btn=(UIButton*)[_tabBarView viewWithTag:100+i];
        btn.enabled=YES;
        
    }
    sender.enabled=NO;
    self.selectedIndex=sender.tag-100;
}


@end
